package cn.edu.cqupt.cxcy.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.cqupt.cxcy.dao.AdminDao;
import cn.edu.cqupt.cxcy.dto.AdminImpl;
import cn.edu.cqupt.cxcy.util.Validate;


/**
 * 管理员后台主页
 * @author Dancer-mno
 * @date 2015年10月17日
 */
public class AdminAjaxDel extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String type = request.getParameter("type"); //类别
		int id = Validate.stringIsNO(request.getParameter("id"))?Integer.parseInt(request.getParameter("id")) : 0; //类别
		AdminDao admin = new AdminImpl();
		boolean flag = false;
		// 主url  /admin/del 返回类型 text/html
		// 投资人  /admin/del?type=inve&&id=? 成功返回:true;失败返回false
		// 项目      /admin/del?type=proj&&id=? 成功返回:true;失败返回false
		// 团队      /admin/del?type=team&&id=? 成功返回:true;失败返回false
		// 导师      /admin/del?type=teac&&id=? 成功返回:true;失败返回false
		// 新闻      /admin/del?type=news&&id=? 成功返回:true;失败返回false
		if(type == null) {
			
		} else if("inve".equals(type)) {
			flag = admin.delInve(id);
		} else if("proj".equals(type)) {
			flag = admin.delPro(id);
		} else if("team".equals(type)) {
			flag = admin.delTeam(id);
		} else if("teac".equals(type)) {
			flag = admin.delTutor(id);
		} else if("news".equals(type)) {
			flag = admin.delNews(id);
		}
		System.out.println("id:" + id + ",type:" + type);
		response.setContentType("text/html;charset=utf-8");
		response.setHeader("pragma","no-cache");
		response.setHeader("cache-control","no-cache");
		PrintWriter out = response.getWriter();
		out.print(flag);
		out.flush();
		out.close();
	}

}
